home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / animutil / fastgfx / fg303b / manuals.arj / USER10.DOC < prev    next >
Encoding:
Text File  |  1993-10-02  |  72.3 KB  |  1,735 lines

  1. Chapter 10
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Bit-Mapped Images
  8.  
  9. 190   Fastgraph User's Guide
  10.  
  11.  
  12.  
  13. Overview
  14.  
  15.      In this chapter, we'll continue our discussion of images by
  16. concentrating on an important class of images called bit-mapped images.
  17. Fastgraph includes routines to display, retrieve, and manipulate bit-mapped
  18. images in mode-specific and mode-independent formats.  This chapter will
  19. discuss the Fastgraph routines that deal with both classes of bit-mapped
  20. images.
  21.  
  22.      Displaying bit-mapped images is an essential part of animation with
  23. Fastgraph.  While the image files discussed in the previous chapter are
  24. useful for displaying backgrounds or importing pictures from other sources,
  25. an animation sequence can only achieve its speed through the bit-mapped image
  26. display routines described in this chapter, along with the block transfer
  27. routines of the next chapter.
  28.  
  29.  
  30. Mode-Independent Bit-Mapped Images
  31.  
  32.      This section will discuss the image display routines that use the same
  33. bit-mapped image format for all graphics video modes.  Another class of
  34. routines, described in the next section, use different formats for different
  35. video modes.  While these mode-independent image display routines are more
  36. general, they achieve this generality at the sake of execution speed.  This
  37. may especially be a concern if the image is large, or if speed is critical in
  38. an application (as in arcade-style graphics).  For many programs, however,
  39. the mode-independent routines provide all the image display capability
  40. needed.
  41.  
  42.      Let's begin by returning to an example of a very simple image -- the
  43. triangle introduced in the previous chapter:
  44.  
  45.                               . . . . * . . . .
  46.                               . . . * x * . . .
  47.                               . . * x x x * . .
  48.                               . * x x x x x * .
  49.                               * * * * * * * * *
  50.  
  51. Recall that the triangle's perimeter is a different color than its interior
  52. pixels, and to use this image with Fastgraph, we must inscribe the triangle
  53. in a rectangular area.  As before, our triangle is nine pixels wide at its
  54. base and five pixels high.  The pixels indicated by an asterisk (*) are the
  55. triangle's perimeter, while those indicated by an x represent its interior
  56. points.  We need to distinguish between these pixels because they will be
  57. different colors.  The pixels shown as periods (.) are not part of the
  58. triangle itself.  They are required to make the image rectangular, so from
  59. Fastgraph's perspective they are indeed part of the image.
  60.  
  61.      The Fastgraph routine fg_drawmap is a suitable routine for drawing our
  62. triangle.  To use fg_drawmap, we must create separate bit maps for each color
  63. in the image (excluding the points used to fill the rectangular region, which
  64. are considered transparent).  In this example, we will thus need two bit
  65. maps -- one for the perimeter points, and one for the interior points.  Let's
  66. break the image into these two bit maps.
  67.                                           Chapter 10:  Bit-Mapped Images   191
  68.  
  69.  
  70.                   . . . . * . . . .        . . . . . . . . .
  71.                   . . . * . * . . .        . . . . x . . . .
  72.                   . . * . . . * . .        . . . x x x . . .
  73.                   . * . . . . . * .        . . x x x x x . .
  74.                   * * * * * * * * *        . . . . . . . . .
  75.  
  76.                   perimeter points          interior points
  77.  
  78.      The next step is to convert these two bit maps into their binary
  79. representations.  Just as there are eight bits in a byte, we will create a
  80. data structure (an array in this case) with each byte holding eight pixels.
  81. Bits that are set (1) indicate the corresponding pixel will appear displayed
  82. in the color associated with that bit map.  Bits that are reset (0) leave the
  83. corresponding pixel unchanged.  The size of each bit map array must be at
  84. least 10 bytes because each bit map contains five rows with nine pixels in
  85. each row (that is, two bytes are required for each row of the image).  Hence,
  86. when we convert these bit maps to their binary representations, and
  87. subsequently to their hexadecimal equivalent, the results will appear as
  88. shown below.  The boldface bits represent the actual image; the other bits
  89. are filler bits needed to complete each row of the bit maps after the ninth
  90. pixel.  All filler bits must be zero.
  91.  
  92.               0 0 0 0 1 0 0 0   0 0 0 0 0 0 0 0         08   00
  93.  
  94.               0 0 0 1 0 1 0 0   0 0 0 0 0 0 0 0         14   00
  95.  
  96.               0 0 1 0 0 0 1 0   0 0 0 0 0 0 0 0         22   00
  97.  
  98.               0 1 0 0 0 0 0 1   0 0 0 0 0 0 0 0         41   00
  99.  
  100.               1 1 1 1 1 1 1 1   1 0 0 0 0 0 0 0         FF   80
  101.  
  102.                               perimeter bit map
  103.  
  104.  
  105.               0 0 0 0 0 0 0 0   0 0 0 0 0 0 0 0         00   00
  106.  
  107.               0 0 0 0 1 0 0 0   0 0 0 0 0 0 0 0         08   00
  108.  
  109.               0 0 0 1 1 1 0 0   0 0 0 0 0 0 0 0         1C   00
  110.  
  111.               0 0 1 1 1 1 1 0   0 0 0 0 0 0 0 0         3E   00
  112.  
  113.               0 0 0 0 0 0 0 0   0 0 0 0 0 0 0 0         00   00
  114.  
  115.                                interior bit map
  116.  
  117.      The next question is the order in which the bit maps are stored in the
  118. corresponding data structures.  Since our data structure is an array, it is
  119. only necessary to show the relationship of the subscripts to the bit map
  120. structures above.  The next diagram shows the subscript order for the case of
  121. a two-column by five-row bit map.
  122.  
  123.                                   [8]   [9]
  124.  
  125.                                   [6]   [7]
  126. 192   Fastgraph User's Guide
  127.  
  128.  
  129.                                   [4]   [5]
  130.  
  131.                                   [2]   [3]
  132.  
  133.                                   [0]   [1]
  134.  
  135.      From this diagram, we see the first element of the array (that is, the
  136. element with subscript [0]) represents the lower left corner of the image.
  137. The subscript progression then continues right until reaching the end of the
  138. first row.  It then resumes at the leftmost element of the second row and
  139. continues to the right until the end of that row.  It continues in this
  140. manner for all remaining rows.
  141.  
  142.      We are now ready to present an example program to display our triangle.
  143. The program will use the Fastgraph routine fg_drawmap, which expects three
  144. arguments.  The first argument is the bit map array (passed by reference),
  145. the second is the width of the bit map in bytes, and the last is the height
  146. of the bit map in pixel rows.  The fg_drawmap routine displays the image such
  147. that its lower left corner is at the graphics cursor position on the active
  148. video page.  The routine has no effect in text video modes.  Additionally,
  149. fg_drawmap displays the image using the current color index, which means we
  150. will need to call fg_drawmap once for each color in the image.
  151.  
  152.      Example 10-1 runs in any 320 by 200 color graphics mode (it could be
  153. made to run in mode 12 too, but that would detract from the purpose of the
  154. example).  After establishing the video mode, the program uses fg_rect to
  155. fill the entire screen with a gray rectangle (white in CGA).  Next, the
  156. program establishes (156,101) as the graphics cursor position; this causes
  157. the triangle to be centered on the screen.  The two calls to fg_drawmap, one
  158. for each color in the image, actually display the triangle.  Note especially
  159. how fg_setcolor is used before each call to fg_drawmap to define the current
  160. color index.  The result is a triangle with a blue perimeter (cyan in CGA)
  161. and green interior (magenta in CGA).
  162.  
  163.                                 Example 10-1.
  164.  
  165.              #include <fastgraf.h>
  166.              #include <stdio.h>
  167.              #include <stdlib.h>
  168.              void main(void);
  169.  
  170.              char perimeter[] = {
  171.                 0xFF,0x80,0x41,0x00,0x22,0x00,0x14,0x00,0x08,0x00
  172.                 };
  173.              char interior[] = {
  174.                 0x00,0x00,0x3E,0x00,0x1C,0x00,0x08,0x00,0x00,0x00
  175.                 };
  176.  
  177.              void main()
  178.              {
  179.                 int old_mode, new_mode;
  180.  
  181.                 new_mode = fg_bestmode(320,200,1);
  182.                 if (new_mode < 0 || new_mode == 12) {
  183.                    printf("This program requires a 320 ");
  184.  
  185.                                           Chapter 10:  Bit-Mapped Images   193
  186.  
  187.  
  188.                    printf("x 200 color graphics mode.\n");
  189.                    exit(1);
  190.                    }
  191.  
  192.                 old_mode = fg_getmode();
  193.                 fg_setmode(new_mode);
  194.  
  195.                 fg_setcolor(7);
  196.                 fg_rect(0,319,0,199);
  197.  
  198.                 fg_move(156,101);
  199.                 fg_setcolor(1);
  200.                 fg_drawmap(perimeter,2,5);
  201.                 fg_setcolor(2);
  202.                 fg_drawmap(interior,2,5);
  203.                 fg_waitkey();
  204.  
  205.                 fg_setmode(old_mode);
  206.                 fg_reset();
  207.              }
  208.  
  209.      The different color bit maps used by fg_drawmap do not all have to be
  210. the same size.  In our triangle example, the perimeter is 9 pixels wide by 5
  211. pixels high, but the interior is only 5 pixels wide by 3 pixels high.  Hence,
  212. the bit map for the interior pixels only requires one byte for each of its
  213. three rows, so we can store it in a three-byte array.  Its structure would
  214. be:
  215.  
  216.                                   [2]   08
  217.  
  218.                                   [1]   1C
  219.  
  220.                                   [0]   3E
  221.  
  222.      Example 10-2 is similar to example 10-1, but it uses a three-byte array
  223. for the interior bit map.  Note the second call to fg_move in this example.
  224. It is needed because the bottom row of the smaller interior bit map
  225. corresponds to the second row of the larger perimeter bit map.  In other
  226. words, the interior bit map must be displayed one row above the perimeter bit
  227. map.
  228.  
  229.                                 Example 10-2.
  230.  
  231.              #include <fastgraf.h>
  232.              #include <stdio.h>
  233.              #include <stdlib.h>
  234.              void main(void);
  235.  
  236.              char perimeter[] = {
  237.                 0xFF,0x80,0x41,0x00,0x22,0x00,0x14,0x00,0x08,0x00
  238.                 };
  239.              char interior[] = {
  240.                 0x3E,0x1C,0x08
  241.                 };
  242.  
  243. 194   Fastgraph User's Guide
  244.  
  245.  
  246.  
  247.              void main()
  248.              {
  249.                 int old_mode, new_mode;
  250.  
  251.                 new_mode = fg_bestmode(320,200,1);
  252.                 if (new_mode < 0 || new_mode == 12) {
  253.                    printf("This program requires a 320 ");
  254.                    printf("x 200 color graphics mode.\n");
  255.                    exit(1);
  256.                    }
  257.  
  258.                 old_mode = fg_getmode();
  259.                 fg_setmode(new_mode);
  260.  
  261.                 fg_setcolor(7);
  262.                 fg_rect(0,319,0,199);
  263.  
  264.                 fg_move(156,101);
  265.                 fg_setcolor(1);
  266.                 fg_drawmap(perimeter,2,5);
  267.                 fg_move(156,100);
  268.                 fg_setcolor(2);
  269.                 fg_drawmap(interior,1,3);
  270.                 fg_waitkey();
  271.  
  272.                 fg_setmode(old_mode);
  273.                 fg_reset();
  274.              }
  275.  
  276.  
  277.      In example 10-2, the time required to execute the second call to fg_move
  278. may not be worth the saving of 7 bytes.  When array space is critical, or
  279. when the images are larger, the use of smaller bit maps for certain colors
  280. may be more valuable.
  281.  
  282.      Yet another possibility for example 10-2 would be to shift the elements
  283. of the interior bit map two pixels to the left.  In this way, the bit map
  284. would be aligned against the left side of the array, just as the perimeter
  285. bit map is.  The three values comprising the interior bit map would then
  286. become F8, 70, and 20.  We also would need to change the x coordinate in the
  287. second call to fg_move from 156 to 158.
  288.  
  289.  
  290. Mode-Specific Bit-Mapped Images
  291.  
  292.      This section will discuss the image display routines that use bit-mapped
  293. image formats that are specific to each text and graphics video mode.  The
  294. different image formats closely resemble the structure of video memory in
  295. each mode, so these routines are much faster than displaying mode-independent
  296. bit maps with fg_drawmap.  If you use the mode-specific bit maps in a program
  297. that supports several video modes, there will be some additional programming
  298. that is not needed when using mode-independent bit maps.  Usually, however,
  299. your efforts will be rewarded with significantly faster graphics.
  300.                                           Chapter 10:  Bit-Mapped Images   195
  301.  
  302.  
  303.      We'll demonstrate the use of mode-specific bit maps in graphics modes
  304. with the familiar two-color triangle whose pixel representation appears
  305. below.
  306.  
  307.                               . . . . * . . . .
  308.                               . . . * x * . . .
  309.                               . . * x x x * . .
  310.                               . * x x x x x * .
  311.                               * * * * * * * * *
  312.  
  313.      As before, our triangle is nine pixels wide at its base and five pixels
  314. high.  The pixels indicated by an asterisk (*) are the triangle's perimeter,
  315. while those indicated by an x represent its interior points.  We need to
  316. distinguish between these pixels because they will be different colors.  The
  317. pixels shown as periods (.) are not part of the triangle itself.  They are
  318. required to make the image rectangular, so from Fastgraph's perspective they
  319. are indeed part of the image.
  320.  
  321.  
  322. Regular Images
  323.  
  324.      The Fastgraph routine fg_drwimage displays regular mode-specific bit-
  325. mapped images (by regular, we mean an image that is neither clipped nor
  326. rotated).  Its arguments are the same as for the fg_drawmap routine, and the
  327. bit map array's subscript order is also the same as for fg_drawmap.  The
  328. major difference is the bit map structure -- we combine the information for
  329. all colors into a single bit map, in a way consistent with the structure of
  330. video memory for the various modes.  As with the other image display
  331. routines, fg_drwimage displays the image on the active video page with its
  332. lower left corner at the graphics cursor position (or the text cursor
  333. position for text modes).  We'll now examine the use of fg_drwimage in
  334. several video modes.
  335.  
  336. CGA four-color graphics modes
  337.  
  338.      In the four-color CGA graphics modes (modes 4 and 5), each pixel can
  339. assume a value between 0 and 3.  This means it takes two bits to represent a
  340. pixel, or put another way, each byte of video memory holds four pixels.  Our
  341. triangle image is nine pixels wide, so three bytes are needed for each row of
  342. the image.  Because the image is five pixels high, we need a bit map array of
  343. at least 15 bytes (five rows times three bytes per row) to hold the image.
  344.  
  345.      The image's binary representation and its hexadecimal equivalent for the
  346. four-color CGA graphics modes are shown below.  The binary values in boldface
  347. represent the actual image; the others are the filler bits needed to complete
  348. each row of the bit map after the ninth pixel.  We have coded the perimeter
  349. pixels to be color 1 (01 binary) and the interior pixels to be color 2 (10
  350. binary).  Any pixel whose value is zero (00 binary) is transparent and will
  351. thus leave the contents of video memory at that position unchanged.
  352.  
  353.          00 00 00 00   01 00 00 00   00 00 00 00         00   40   00
  354.  
  355.          00 00 00 01   10 01 00 00   00 00 00 00         01   90   00
  356.  
  357.          00 00 01 10   10 10 01 00   00 00 00 00         06   A4   00
  358.  
  359. 196   Fastgraph User's Guide
  360.  
  361.  
  362.          00 01 10 10   10 10 10 01   00 00 00 00         1A   A9   00
  363.  
  364.          01 01 01 01   01 01 01 01   01 00 00 00         55   55   40
  365.  
  366.      Example 10-3 uses this mode-specific bit map to display the triangle in
  367. the standard CGA four-color graphics mode (mode 4).  After establishing the
  368. video mode, the program uses fg_rect to fill the entire screen with a white
  369. rectangle.  Next, the program establishes (156,101) as the graphics cursor
  370. position; this causes the triangle to be centered on the screen.  The call to
  371. fg_drwimage produces a triangle with a cyan perimeter (color 1) and a magenta
  372. interior (color 2).
  373.  
  374.                                 Example 10-3.
  375.  
  376.               #include <fastgraf.h>
  377.               #include <stdio.h>
  378.               #include <stdlib.h>
  379.               void main(void);
  380.  
  381.               char triangle[] = {
  382.                  0x55,0x55,0x40, 0x1A,0xA9,0x00, 0x06,0xA4,0x00,
  383.                  0x01,0x90,0x00, 0x00,0x40,0x00
  384.                  };
  385.  
  386.               void main()
  387.               {
  388.                  int old_mode;
  389.  
  390.                  if (fg_testmode(4,1) == 0) {
  391.                     printf("This program requires a 320 ");
  392.                     printf("x 200 CGA graphics mode.\n");
  393.                     exit(1);
  394.                     }
  395.  
  396.                  old_mode = fg_getmode();
  397.                  fg_setmode(4);
  398.  
  399.                  fg_setcolor(7);
  400.                  fg_rect(0,319,0,199);
  401.  
  402.                  fg_move(156,101);
  403.                  fg_drwimage(triangle,3,5);
  404.                  fg_waitkey();
  405.  
  406.                  fg_setmode(old_mode);
  407.                  fg_reset();
  408.               }
  409.  
  410.  
  411. CGA two-color graphics mode
  412.  
  413.      In the two-color CGA graphics mode (mode 6), each pixel can assume the
  414. values 0 or 1.  This means it takes just one bit to represent a pixel, so
  415. each byte of video memory holds eight pixels.  Our triangle image is nine
  416. pixels wide, so two bytes are needed for each row of the image.  Because the
  417.                                           Chapter 10:  Bit-Mapped Images   197
  418.  
  419.  
  420. image is five pixels high, we need a bit map array of at least 10 bytes (five
  421. rows times two bytes per row) to hold the image.
  422.  
  423.      The image's binary representation and its hexadecimal equivalent for the
  424. two-color CGA graphics mode is shown below.  The binary values in boldface
  425. represent the actual image; the others are the filler bits needed to complete
  426. each row of the bit map after the ninth pixel.  We have coded both the
  427. perimeter pixels and the interior pixels to be color 1.  Any pixel whose
  428. value is zero is transparent and will thus leave the contents of video memory
  429. at that position unchanged.
  430.  
  431.               0 0 0 0 1 0 0 0   0 0 0 0 0 0 0 0         08   00
  432.  
  433.               0 0 0 1 1 1 0 0   0 0 0 0 0 0 0 0         1C   00
  434.  
  435.               0 0 1 1 1 1 1 0   0 0 0 0 0 0 0 0         3E   00
  436.  
  437.               0 1 1 1 1 1 1 1   0 0 0 0 0 0 0 0         7F   00
  438.  
  439.               1 1 1 1 1 1 1 1   1 0 0 0 0 0 0 0         FF   80
  440.  
  441.      Example 10-4 uses this mode-specific bit map to display the triangle in
  442. the CGA two-color graphics mode (mode 6).  After establishing the video mode,
  443. the program establishes (316,101) as the graphics cursor position; this
  444. causes the triangle to be centered on the screen.  The call to fg_drwimage
  445. produces a solid triangle.
  446.  
  447.                                 Example 10-4.
  448.  
  449.                   #include <fastgraf.h>
  450.                   #include <stdio.h>
  451.                   #include <stdlib.h>
  452.                   void main(void);
  453.  
  454.                   char triangle[] = {
  455.                      0xFF,0x80, 0x7F,0x00, 0x3E,0x00,
  456.                      0x1C,0x00, 0x08,0x00
  457.                      };
  458.  
  459.                   void main()
  460.                   {
  461.                      int old_mode;
  462.  
  463.                      if (fg_testmode(6,1) == 0) {
  464.                         printf("This program requires a ");
  465.                         printf("CGA graphics mode.\n");
  466.                         exit(1);
  467.                         }
  468.  
  469.                      old_mode = fg_getmode();
  470.                      fg_setmode(6);
  471.  
  472.                      fg_move(316,101);
  473.                      fg_drwimage(triangle,2,5);
  474.                      fg_waitkey();
  475.  
  476. 198   Fastgraph User's Guide
  477.  
  478.  
  479.  
  480.                      fg_setmode(old_mode);
  481.                      fg_reset();
  482.                   }
  483.  
  484.  
  485. Tandy/PCjr 16-color graphics mode
  486.  
  487.      The structure of the mode-specific bit maps for the Tandy/PCjr 16-color
  488. graphics mode (mode 9) is the same as the mode-specific bit map structure for
  489. the EGA/VGA/SVGA 16-color graphics modes discussed later in this section.
  490.  
  491. Hercules graphics modes
  492.  
  493.      The structure of the mode-specific bit maps for the Hercules graphics
  494. modes (modes 11 and 12) is the same as two of the CGA graphics modes.  For
  495. the standard Hercules graphics mode (mode 11), please refer to the discussion
  496. of CGA two-color (mode 6) bit maps.  For the low-resolution Hercules graphics
  497. mode (mode 12), please refer to the discussion of the CGA four-color (mode 4)
  498. bit maps.
  499.  
  500. EGA/VGA/SVGA 16-color graphics modes
  501.  
  502.      In the native EGA and VGA graphics modes (modes 13 through 18) and the
  503. 16-color SVGA graphics modes (modes 28 and 29), each pixel can assume a value
  504. between 0 and 15.  This means it takes four bits to represent a pixel, so
  505. each byte of the bit map holds two pixels.  Our triangle image is nine pixels
  506. wide, so five bytes are needed for each row of the image.  Because the image
  507. is five pixels high, we need a bit map array of at least 25 bytes (five rows
  508. times five bytes per row) to hold the image.
  509.  
  510.      In these modes, it is easy to develop the hexadecimal representation of
  511. a bit map without first producing its binary equivalent.  This is because a
  512. pixel value and a hexadecimal digit each occupy four bits.  The triangle's
  513. hexadecimal representation for these video modes is shown below.  The pixels
  514. in boldface represent the actual image; the others are the filler values
  515. needed to complete each row of the bit map after the ninth pixel.  We have
  516. chosen to display the perimeter pixels in color 1 and the interior pixels in
  517. color 2.  Any pixel whose value is zero is transparent and will thus leave
  518. the contents of video memory at that position unchanged.
  519.  
  520.                             00   00   10   00   00
  521.  
  522.                             00   01   21   00   00
  523.  
  524.                             00   12   22   10   00
  525.  
  526.                             01   22   22   21   00
  527.  
  528.                             11   11   11   11   10
  529.  
  530.      Example 10-5 is similar to example 10-3, but it uses the 320 by 200 EGA
  531. graphics mode (mode 13) and the mode-specific bit map just constructed to
  532. display the triangle.  The call to fg_drwimage produces a triangle with a
  533. blue perimeter (color 1) and a green interior (color 2).
  534.                                           Chapter 10:  Bit-Mapped Images   199
  535.  
  536.  
  537.  
  538.                                 Example 10-5.
  539.  
  540.                 #include <fastgraf.h>
  541.                 #include <stdio.h>
  542.                 #include <stdlib.h>
  543.                 void main(void);
  544.  
  545.                 char triangle[] = {
  546.                    0x11,0x11,0x11,0x11,0x10,
  547.                    0x01,0x22,0x22,0x21,0x00,
  548.                    0x00,0x12,0x22,0x10,0x00,
  549.                    0x00,0x01,0x21,0x00,0x00,
  550.                    0x00,0x00,0x10,0x00,0x00
  551.                    };
  552.  
  553.                 void main()
  554.                 {
  555.                    int old_mode;
  556.  
  557.                    if (fg_testmode(13,1) == 0) {
  558.                       printf("This program requires a 320 ");
  559.                       printf("x 200 EGA graphics mode.\n");
  560.                       exit(1);
  561.                       }
  562.  
  563.                    old_mode = fg_getmode();
  564.                    fg_setmode(13);
  565.  
  566.                    fg_setcolor(7);
  567.                    fg_rect(0,319,0,199);
  568.  
  569.                    fg_move(156,101);
  570.                    fg_drwimage(triangle,5,5);
  571.                    fg_waitkey();
  572.  
  573.                    fg_setmode(old_mode);
  574.                    fg_reset();
  575.                 }
  576.  
  577.  
  578. 256-color graphics modes
  579.  
  580.      In the 256-color graphics modes (modes 19 through 27), each pixel can
  581. assume a value between 0 and 255 (FF hex).  This means it takes eight bits to
  582. represent a pixel, or each byte of video memory holds one pixel.  Our
  583. triangle image is nine pixels wide, so nine bytes are needed for each row of
  584. the image.  Because the image is five pixels high, we need a bit map array of
  585. at least 45 bytes (five rows times nine bytes per row) to hold the image.
  586. Note we will never need any filler bits in the 256-color video modes.
  587.  
  588.      It is especially simple to develop the bit map for an image in the 256-
  589. color modes because each byte holds exactly one pixel.  The triangle's
  590. hexadecimal representation for the 256-color graphics modes is shown below.
  591. As before, we have coded the perimeter pixels to be color 1 (01 hex) and the
  592. interior pixels to be color 2 (02 hex).  Any pixel whose value is zero is
  593. 200   Fastgraph User's Guide
  594.  
  595.  
  596. transparent and will thus leave the contents of video memory at that position
  597. unchanged.
  598.  
  599.                   00   00   00   00   01   00   00   00   00
  600.  
  601.                   00   00   00   01   02   01   00   00   00
  602.  
  603.                   00   00   01   02   02   02   01   00   00
  604.  
  605.                   00   01   02   02   02   02   02   01   00
  606.  
  607.                   01   01   01   01   01   01   01   01   01
  608.  
  609.      Example 10-6 is also similar to example 10-3, but it uses the MCGA 256-
  610. color graphics mode (mode 19) and the mode-specific bit map just constructed
  611. to display the triangle.  The call to fg_drwimage produces a triangle with a
  612. blue perimeter (color 1) and a green interior (color 2).
  613.  
  614.                                 Example 10-6.
  615.  
  616.                #include <fastgraf.h>
  617.                #include <stdio.h>
  618.                #include <stdlib.h>
  619.                void main(void);
  620.  
  621.                char triangle[] = {
  622.                   0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  623.                   0x00,0x01,0x02,0x02,0x02,0x02,0x02,0x01,0x00,
  624.                   0x00,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,
  625.                   0x00,0x00,0x00,0x01,0x02,0x01,0x00,0x00,0x00,
  626.                   0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00
  627.                   };
  628.  
  629.                void main()
  630.                {
  631.                   int old_mode;
  632.  
  633.                   if (fg_testmode(19,1) == 0) {
  634.                      printf("This program requires a 320 ");
  635.                      printf("x 200 MCGA graphics mode.\n");
  636.                      exit(1);
  637.                      }
  638.  
  639.                   old_mode = fg_getmode();
  640.                   fg_setmode(19);
  641.  
  642.                   fg_setcolor(7);
  643.                   fg_rect(0,319,0,199);
  644.  
  645.                   fg_move(156,101);
  646.                   fg_drwimage(triangle,9,5);
  647.                   fg_waitkey();
  648.  
  649.                   fg_setmode(old_mode);
  650.                   fg_reset();
  651.                }
  652.                                           Chapter 10:  Bit-Mapped Images   201
  653.  
  654.  
  655.      Sometimes you may need to include black pixels that are not transparent
  656. in a mode-specific bit-mapped image.  The easiest way to do this is to use
  657. fg_palette or fg_setrgb to make an unused color index black and then use that
  658. color index for non-transparent black pixels.  For example, calling
  659. fg_palette(8,0) in a 16-color graphics mode would display color 8 pixels as
  660. black.  Similarly, fg_setrgb(248,0,0,0) in a 256-color graphics mode would
  661. display color 248 pixels as black.  The choice of colors 8 and 248 in these
  662. examples is arbitrary; any unused color will do.  Another possibility is to
  663. use masking maps, discussed later in this chapter.
  664.  
  665.  
  666. Text Modes
  667.  
  668.      You also can use the fg_drwimage routine to display images in text video
  669. modes (modes 0, 1, 2, 3, and 7).  As one might expect, the image structure in
  670. the text modes is rather different from the graphics modes.  In Chapter 5 we
  671. saw that each character cell on the screen actually consists of a character
  672. and an attribute.  The character value determines what character is
  673. displayed, while the attribute value controls the character's appearance.
  674. The structure of the attribute is:
  675.  
  676.                   bits   attribute
  677.  
  678.                    0-3   foreground color
  679.                    4-6   background color
  680.                     7    blinking
  681.  
  682.      The text mode image structure used with fg_drwimage also consists of a
  683. series of characters and attributes.  For example, the following diagram
  684. illustrates the structure of an image that is three characters wide and two
  685. characters high.
  686.  
  687.  
  688.                    char   attr   char   attr   char   attr
  689.  
  690.                    char   attr   char   attr   char   attr
  691.  
  692.  
  693.      To illustrate the use of fg_drwimage in a text video mode, we'll display
  694. the phrase "hello there" on two different lines in the center of the screen.
  695. Furthermore, let's assume we would like the first character of each word to
  696. appear in foreground color 1, the second in color 2, and so forth.  Our image
  697. will consist of two lines each containing five characters, and each character
  698. requires two bytes of storage (one for the character and another for its
  699. attribute), so we'll need a 20-byte array for holding the image.  The array
  700. really doesn't hold a bit map as in the graphics modes, so in the text modes
  701. the first argument passed to fg_drwimage is instead called the image array.
  702. In our example, the structure of the image array is:
  703.  
  704.            'h'    1    'e'    2    'l'    3    'l'    4    'o'    5
  705.  
  706.            't'    1    'h'    2    'e'    3    'r'    4    'e'    5
  707.  
  708. 202   Fastgraph User's Guide
  709.  
  710.  
  711. The subscript order that fg_drwimage uses for text modes is the same as for
  712. the graphics modes.  For our five-row by two-column image, this means the
  713. array subscripts would be numbered as follows:
  714.  
  715.               [10] [11] [12] [13] [14] [15] [16] [17] [18] [19]
  716.  
  717.                [0]  [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]
  718.  
  719.      Depending on the character and attribute values in the image array,
  720. fg_drwimage can display new characters and attributes, new characters leaving
  721. the existing attribute unchanged, new attributes leaving the existing
  722. character unchanged, or leave both the existing character and attribute
  723. unchanged in video memory.  To keep an existing character or attribute,
  724. simply specify a value of 0 in the corresponding element of the image array.
  725. This capability is analogous to the fact that zero-valued pixels in graphics
  726. mode bit maps leave video memory unchanged.
  727.  
  728.      Example 10-7 demonstrates the use of the fg_drwimage routine in the 80-
  729. column color text mode (mode 3).  After establishing the video mode and
  730. making the cursor invisible, the program calls fg_drwimage to display the
  731. "hello there" image just discussed (note we pass the dimensions of the image
  732. array as the number of bytes, not the number of characters).  The program
  733. waits for a keystroke and then calls fg_drwimage again, passing a different
  734. image array (called "image") of the same size.  This array changes the first
  735. letter of both words from lower case to upper case (leaving the attribute
  736. unchanged), and it makes the remaining characters have the same attribute as
  737. the first character.  This is done in part by using zero-valued characters
  738. and attributes to leave video memory unchanged.  After waiting for another
  739. keystroke, the program exits.
  740.  
  741.                                 Example 10-7.
  742.  
  743.                     #include <fastgraf.h>
  744.                     void main(void);
  745.  
  746.                     char hello[] = {
  747.                        't',1, 'h',2, 'e',3, 'r',4, 'e',5,
  748.                        'h',1, 'e',2, 'l',3, 'l',4, 'o',5
  749.                        };
  750.  
  751.                     char image[] = {
  752.                        'T',0, 0,1, 0,1, 0,1, 0,1,
  753.                        'H',0, 0,1, 0,1, 0,1, 0,1
  754.                        };
  755.  
  756.                     void main()
  757.                     {
  758.                        int old_mode;
  759.  
  760.                        old_mode = fg_getmode();
  761.                        fg_setmode(3);
  762.                        fg_cursor(0);
  763.  
  764.                        fg_locate(12,37);
  765.  
  766.                                           Chapter 10:  Bit-Mapped Images   203
  767.  
  768.  
  769.                        fg_drwimage(hello,10,2);
  770.                        fg_waitkey();
  771.  
  772.                        fg_drwimage(image,10,2);
  773.                        fg_waitkey();
  774.  
  775.                        fg_setmode(old_mode);
  776.                        fg_reset();
  777.                     }
  778.  
  779.  
  780.  
  781. Clipped Images
  782.  
  783.      The fg_drwimage routine displays an image without regard to the current
  784. clipping limits.  If you want the image to be displayed with respect to the
  785. clipping limits (as established by the most recent call to fg_setclip), you
  786. should use the fg_clpimage routine instead of fg_drwimage.  Fg_clpimage takes
  787. the same three arguments as fg_drwimage, and also displays the image such
  788. that its lower left corner is at the graphics cursor position.  Unlike
  789. fg_drwimage, the fg_clpimage routine has no effect when used in a text video
  790. mode.  Because of the additional overhead involved in checking the clipping
  791. limits, fg_clpimage is not as fast as fg_drwimage.
  792.  
  793.  
  794. Reversed Images
  795.  
  796.      The fg_revimage routine displays an image reversed (that is, mirrored
  797. about the y-axis).  Fg_revimage takes the same three arguments as
  798. fg_drwimage, and also displays the image such that its lower left corner is
  799. at the graphics cursor position.  The fg_revimage routine has no effect when
  800. used in a text video mode.
  801.  
  802.  
  803. Reversed Clipped Images
  804.  
  805.      The fg_flpimage routine combines the effects of the fg_revimage and
  806. fg_clpimage routines -- it displays a reversed image with respect to the
  807. current clipping limits.  Fg_flpimage takes the same three arguments as
  808. fg_drwimage, and also displays the image such that its lower left corner is
  809. at the graphics cursor position.  Like the fg_clpimage routine, fg_flpimage
  810. has no effect when used in a text video mode.
  811.  
  812.  
  813. Images Without Transparent Pixels
  814.  
  815.      The fg_putimage routine is the same as fg_drwimage except it does not
  816. consider color 0 pixels to be transparent.  Because it does not need to check
  817. for transparent pixels, fg_putimage is faster than fg_drwimage.  Using
  818. fg_putimage is recommended for cases where transparency is not an issue.
  819.  
  820.  
  821. Some Examples
  822.  
  823.      Example 10-8 illustrates the use of the fg_drwimage, fg_clpimage,
  824. fg_revimage, fg_flpimage, and fg_putimage routines in the standard CGA four-
  825. 204   Fastgraph User's Guide
  826.  
  827.  
  828. color graphics mode (mode 4).  The program uses each of these routines to
  829. display a small white arrow, as shown in the pixel map below.
  830.  
  831.                              . . . . . . * . . .
  832.                              . . . . . . * * . .
  833.                              * * * * * * * * * .
  834.                              * * * * * * * * * *
  835.                              * * * * * * * * * .
  836.                              . . . . . . * * . .
  837.                              . . . . . . * . . .
  838.  
  839. As before, we must first convert this image to a bit map.  The image is ten
  840. pixels wide and seven high.  In mode 4, each pixel occupies two bits, so we
  841. need a 21-byte array (7 rows by 3 columns) to store the image.  Since we want
  842. to make the arrow white, each pixel will be displayed in color 3 (11 binary).
  843. Here is the bit map and its hexadecimal equivalent for the arrow image in
  844. mode 4 (the actual image is in boldface).
  845.  
  846.          00 00 00 00   00 00 11 00   00 00 00 00         00   0C   00
  847.  
  848.          00 00 00 00   00 00 11 11   00 00 00 00         00   0F   00
  849.  
  850.          11 11 11 11   11 11 11 11   11 00 00 00         FF   FF   C0
  851.  
  852.          11 11 11 11   11 11 11 11   11 11 00 00         FF   FF   F0
  853.  
  854.          11 11 11 11   11 11 11 11   11 00 00 00         FF   FF   C0
  855.  
  856.          00 00 00 00   00 00 11 11   00 00 00 00         00   0F   00
  857.  
  858.          00 00 00 00   00 00 11 00   00 00 00 00         00   0C   00
  859.  
  860.      After establishing the video mode, the program fills the screen with
  861. color 1 pixels and defines a clipping region.  It then uses fg_drwimage to
  862. display the arrow pointing to the right and fg_clpimage to do the same thing,
  863. but with respect to the clipping limits.  Because the left edge of the arrow
  864. is displayed at x=10 and the right clipping limit is at x=15, the call to
  865. fg_clpimage only draws the first six columns of the arrow (that is, it does
  866. not draw the arrow head).
  867.  
  868.      Next, example 10-8 uses fg_revimage to display the arrow pointing to the
  869. left.  To allow for the filler pixels, we must establish the graphics cursor
  870. position two pixels to the left of the position used by fg_drwimage if we
  871. want the tip of the left-pointing arrow to align with the tail of the right-
  872. pointing arrow.  The program then uses fg_flpimage to display an arrow
  873. pointing to the left with regard to the clipping limits.  The call to
  874. fg_flpimage displays the arrow head and the first two columns of the arrow
  875. shaft.  Finally, the program uses fg_putimage to display the unclipped right-
  876. pointing arrow without transparent pixels (this produces a black border
  877. around the arrow).
  878.  
  879.                                 Example 10-8.
  880.  
  881.               #include <fastgraf.h>
  882.               #include <stdio.h>
  883.  
  884.                                           Chapter 10:  Bit-Mapped Images   205
  885.  
  886.  
  887.               #include <stdlib.h>
  888.               void main(void);
  889.  
  890.               char arrow[] = {
  891.                  0x00,0x0C,0x00, 0x00,0x0F,0x00, 0xFF,0xFF,0xC0,
  892.                  0xFF,0xFF,0xF0, 0xFF,0xFF,0xC0, 0x00,0x0F,0x00,
  893.                  0x00,0x0C,0x00
  894.                  };
  895.  
  896.               void main()
  897.               {
  898.                  int old_mode;
  899.  
  900.                  if (fg_testmode(4,1) == 0) {
  901.                     printf("This program requires a 320 ");
  902.                     printf("x 200 CGA graphics mode.\n");
  903.                     exit(1);
  904.                     }
  905.  
  906.                  old_mode = fg_getmode();
  907.                  fg_setmode(4);
  908.                  fg_setcolor(1);
  909.                  fg_fillpage();
  910.                  fg_setclip(0,15,0,199);
  911.  
  912.                  fg_move(10,10);
  913.                  fg_drwimage(arrow,3,7);
  914.                  fg_move(10,20);
  915.                  fg_clpimage(arrow,3,7);
  916.                  fg_move(8,30);
  917.                  fg_revimage(arrow,3,7);
  918.                  fg_move(8,40);
  919.                  fg_flpimage(arrow,3,7);
  920.                  fg_move(8,50);
  921.                  fg_putimage(arrow,3,7);
  922.                  fg_waitkey();
  923.  
  924.                  fg_setmode(old_mode);
  925.                  fg_reset();
  926.               }
  927.  
  928.  
  929.      Example 10-9 is the same as example 10-8, but it uses the low resolution
  930. EGA graphics mode (mode 13).  If we changed the mode number specified in the
  931. calls to fg_testmode and fg_setmode, the program also would run in any 16-
  932. color graphics mode.  In these modes, we store two pixels per byte in the bit
  933. map array, so we need a 35-byte array (7 rows by 5 columns) to store the
  934. image.  Here is the bit map's hexadecimal equivalent for the arrow image in
  935. mode 13, followed by the program to display it.
  936.  
  937.                             00   00   00   F0   00
  938.  
  939.                             00   00   00   FF   00
  940.  
  941.                             FF   FF   FF   FF   F0
  942.  
  943. 206   Fastgraph User's Guide
  944.  
  945.                             FF   FF   FF   FF   FF
  946.  
  947.                             FF   FF   FF   FF   F0
  948.  
  949.                             00   00   00   FF   00
  950.  
  951.                             00   00   00   F0   00
  952.  
  953.  
  954.                                 Example 10-9.
  955.  
  956.                 #include <fastgraf.h>
  957.                 #include <stdio.h>
  958.                 #include <stdlib.h>
  959.                 void main(void);
  960.  
  961.                 char arrow[] = {
  962.                    0x00,0x00,0x00,0xF0,0x00,
  963.                    0x00,0x00,0x00,0xFF,0x00,
  964.                    0xFF,0xFF,0xFF,0xFF,0xF0,
  965.                    0xFF,0xFF,0xFF,0xFF,0xFF,
  966.                    0xFF,0xFF,0xFF,0xFF,0xF0,
  967.                    0x00,0x00,0x00,0xFF,0x00,
  968.                    0x00,0x00,0x00,0xF0,0x00
  969.                    };
  970.  
  971.                 void main()
  972.                 {
  973.                    int old_mode;
  974.  
  975.                    if (fg_testmode(13,1) == 0) {
  976.                       printf("This program requires a 320 ");
  977.                       printf("x 200 EGA graphics mode.\n");
  978.                       exit(1);
  979.                       }
  980.  
  981.                    old_mode = fg_getmode();
  982.                    fg_setmode(13);
  983.                    fg_setcolor(1);
  984.                    fg_fillpage();
  985.                    fg_setclip(0,15,0,199);
  986.  
  987.                    fg_move(10,10);
  988.                    fg_drwimage(arrow,5,7);
  989.                    fg_move(10,20);
  990.                    fg_clpimage(arrow,5,7);
  991.                    fg_move(8,30);
  992.                    fg_revimage(arrow,5,7);
  993.                    fg_move(8,40);
  994.                    fg_flpimage(arrow,5,7);
  995.                    fg_move(8,50);
  996.                    fg_putimage(arrow,5,7);
  997.                    fg_waitkey();
  998.  
  999.                    fg_setmode(old_mode);
  1000.                    fg_reset();
  1001.                 }
  1002.                                           Chapter 10:  Bit-Mapped Images   207
  1003.  
  1004.  
  1005.  
  1006. Retrieving Images
  1007.  
  1008.      Sometimes it is necessary to retrieve an image from video memory and
  1009. store it in one or more arrays as a bit-mapped image.  Fastgraph includes two
  1010. routines, fg_getmap and fg_getimage, for this purpose.  The fg_getmap routine
  1011. retrieves pixels of the current color index and stores them in the mode-
  1012. independent bit map format used by fg_drawmap.  The fg_getimage routine
  1013. retrieves an image and stores it in the mode-specific bit map format used by
  1014. fg_drwimage, fg_clpimage, fg_revimage, fg_flpimage, and fg_putimage.  The
  1015. arguments to fg_getmap and fg_getimage are respectively analogous to those of
  1016. fg_drawmap and fg_drwimage:  the first is an array (passed by reference) to
  1017. receive the bit map, the second is the width of the bit map in bytes, and the
  1018. last is the height of the bit map in pixel rows.  With either routine, the
  1019. graphics cursor position on the active video page defines the lower left
  1020. corner of the image to retrieve.
  1021.  
  1022.      If we want to use the fg_getmap routine to retrieve an image containing
  1023. more than one color, we must call the routine once per color.  In this case
  1024. we'll usually want to pass different bit map arrays to fg_getmap (or perhaps
  1025. different offsets into the same array).  This might seem unusual at first,
  1026. but it parallels the behavior of the fg_drawmap routine.  That is, to display
  1027. a multicolor image using fg_drawmap, we must call it once for each color in
  1028. the image.
  1029.  
  1030.      Example 10-10 demonstrates a typical use of the fg_getmap routine.  The
  1031. program displays the word "text" in the upper left corner of the screen using
  1032. a 320 by 200 graphics mode.  It uses fg_getmap to retrieve the word as an
  1033. image and then displays it in a new position with the fg_drawmap routine.
  1034. Let's look at the program now, and afterward we'll more closely examine the
  1035. screen coordinates and the structure of the bit map array.
  1036.  
  1037.                                 Example 10-10.
  1038.  
  1039.                 #include <fastgraf.h>
  1040.                 #include <stdio.h>
  1041.                 #include <stdlib.h>
  1042.                 void main(void);
  1043.  
  1044.                 void main()
  1045.                 {
  1046.                    char bitmap[32];
  1047.                    int old_mode, new_mode;
  1048.  
  1049.                    new_mode = fg_bestmode(320,200,1);
  1050.                    if (new_mode < 0 || new_mode == 12) {
  1051.                       printf("This program requires a 320 ");
  1052.                       printf("x 200 color graphics mode.\n");
  1053.                       exit(1);
  1054.                       }
  1055.  
  1056.                    old_mode = fg_getmode();
  1057.                    fg_setmode(new_mode);
  1058.  
  1059.                    fg_setcolor(9);
  1060.  
  1061. 208   Fastgraph User's Guide
  1062.  
  1063.  
  1064.                    fg_text("text",4);
  1065.                    fg_waitkey();
  1066.  
  1067.                    fg_move(0,7);
  1068.                    fg_getmap(bitmap,4,8);
  1069.                    fg_move(4,15);
  1070.                    fg_drawmap(bitmap,4,8);
  1071.                    fg_waitkey();
  1072.  
  1073.                    fg_setmode(old_mode);
  1074.                    fg_reset();
  1075.                 }
  1076.  
  1077.      In all 320 by 200 graphics video modes, individual characters are 8
  1078. pixels wide and 8 pixels high.  This means the lower left corner of the (0,0)
  1079. character cell is referenced by the screen coordinates (0,7).  Hence, these
  1080. are the coordinates of the first call to fg_move.  The image retrieved in
  1081. example 10-10 is four characters long (32 pixels wide), so we need a bit map
  1082. array capable of holding 8 rows of 32 pixels (4 bytes) each.  Our bit map
  1083. array is therefore a 32-byte array, logically structured to have 4 columns
  1084. and 8 rows.  These values are the width and height arguments passed to
  1085. fg_getmap and fg_drawmap.
  1086.  
  1087.      After it retrieves the image, example 10-10 displays it one line below
  1088. and one-half character cell (four pixels) to the right of its original
  1089. position.  In other words, the program displays the image four pixels to the
  1090. right of the (1,0) character cell.  The lower left corner of that cell is
  1091. referenced by the screen coordinates (0,15), so the image should appear at
  1092. the position (4,15).  These are the coordinates of the second call to
  1093. fg_move.
  1094.  
  1095.      Example 10-11 illustrates the use of the fg_getmap and fg_drawmap
  1096. routines to retrieve and display a two-color image.  This example is similar
  1097. to example 10-10, but this program first draws a rectangle in the upper left
  1098. corner of the screen and then displays the word "text" on top of the
  1099. rectangle in a different color.  Each character in a 320 by 200 graphics
  1100. video mode is 8 pixels wide and 8 pixels high, so the rectangle must be 32
  1101. pixels wide (4 characters times 8 pixels per character) and 8 pixels high.
  1102. The image to retrieve will be the same size as the rectangle.
  1103.  
  1104.      The image retrieved in example 10-10 required a 32-byte array, logically
  1105. structured to have 4 columns and 8 rows.  Example 10-11 will retrieve an
  1106. image of the same structure, but the image contains two colors instead of
  1107. just one.  This means we need two 32-byte arrays, one for each color, to hold
  1108. the image.  We could instead use a single 64-byte array and pass an offset
  1109. into that array (specifically, &bitmap[32]) for processing the second color.
  1110.  
  1111.                                 Example 10-11.
  1112.  
  1113.                 #include <fastgraf.h>
  1114.                 #include <stdio.h>
  1115.                 #include <stdlib.h>
  1116.                 void main(void);
  1117.  
  1118.                 void main()
  1119.                 {
  1120.                                           Chapter 10:  Bit-Mapped Images   209
  1121.  
  1122.  
  1123.                    char bitmap1[32], bitmap2[32];
  1124.                    int old_mode, new_mode;
  1125.  
  1126.                    new_mode = fg_bestmode(320,200,1);
  1127.                    if (new_mode < 0 || new_mode == 12) {
  1128.                       printf("This program requires a 320 ");
  1129.                       printf("x 200 color graphics mode.\n");
  1130.                       exit(1);
  1131.                       }
  1132.  
  1133.                    old_mode = fg_getmode();
  1134.                    fg_setmode(new_mode);
  1135.  
  1136.                    fg_setcolor(7);
  1137.                    fg_rect(0,31,0,7);
  1138.                    fg_setcolor(9);
  1139.                    fg_text("text",4);
  1140.                    fg_waitkey();
  1141.  
  1142.                    fg_move(0,7);
  1143.                    fg_setcolor(7);
  1144.                    fg_getmap(bitmap1,4,8);
  1145.                    fg_setcolor(9);
  1146.                    fg_getmap(bitmap2,4,8);
  1147.  
  1148.                    fg_move(4,15);
  1149.                    fg_setcolor(7);
  1150.                    fg_drawmap(bitmap1,4,8);
  1151.                    fg_setcolor(9);
  1152.                    fg_drawmap(bitmap2,4,8);
  1153.                    fg_waitkey();
  1154.  
  1155.                    fg_setmode(old_mode);
  1156.                    fg_reset();
  1157.                 }
  1158.  
  1159.  
  1160.      Example 10-12 is similar to example 10-11, but it uses fg_getimage and
  1161. fg_drwimage instead of fg_getmap and fg_drawmap to retrieve and display the
  1162. image.  That is, it uses the mode-specific rather than the mode-independent
  1163. image retrieval and display routines.  When using the mode-specific routines,
  1164. the size of the bit map needed to hold the image depends on the video mode.
  1165. For programs that run in only one video mode, bit map widths are constant,
  1166. but when a program must run in several video modes, the width is variable.
  1167. The Fastgraph routine fg_imagesiz computes the number of bytes required to
  1168. store a mode-specific bit-mapped image of specified dimensions.  Its two
  1169. integer arguments specify the image width and height in pixels.
  1170.  
  1171.      The program computes the image width in bytes by passing a height of 1
  1172. to fg_imagesiz.  The size of the bit map array in example 10-12 is 256 bytes,
  1173. the size required in 256-color graphics modes (32 bytes times 8 bytes).
  1174. Other video modes require less storage, so in these modes only a portion of
  1175. the bit map array will actually be used.  The image width is then used in the
  1176. calls to both fg_getimage and fg_drwimage.
  1177. 210   Fastgraph User's Guide
  1178.  
  1179.                                 Example 10-12.
  1180.  
  1181.                 #include <fastgraf.h>
  1182.                 #include <stdio.h>
  1183.                 #include <stdlib.h>
  1184.                 void main(void);
  1185.  
  1186.                 void main()
  1187.                 {
  1188.                    char bitmap[256];
  1189.                    int old_mode, new_mode;
  1190.                    int width;
  1191.  
  1192.                    new_mode = fg_bestmode(320,200,1);
  1193.                    if (new_mode < 0 || new_mode == 12) {
  1194.                       printf("This program requires a 320 ");
  1195.                       printf("x 200 color graphics mode.\n");
  1196.                       exit(1);
  1197.                       }
  1198.  
  1199.                    old_mode = fg_getmode();
  1200.                    fg_setmode(new_mode);
  1201.                    width = (int)fg_imagesiz(32,1);
  1202.  
  1203.                    fg_setcolor(7);
  1204.                    fg_rect(0,31,0,7);
  1205.                    fg_setcolor(9);
  1206.                    fg_text("text",4);
  1207.                    fg_waitkey();
  1208.  
  1209.                    fg_move(0,7);
  1210.                    fg_getimage(bitmap,width,8);
  1211.                    fg_move(4,15);
  1212.                    fg_drwimage(bitmap,width,8);
  1213.                    fg_waitkey();
  1214.  
  1215.                    fg_setmode(old_mode);
  1216.                    fg_reset();
  1217.                 }
  1218.  
  1219. While this example used an array to store the image, it's usually preferable
  1220. to allocate dynamic memory for this purpose.  We could have done this in
  1221. example 10-12 by calling fg_imagesiz with arguments of 32 (width) and 8
  1222. (height).  The routine's return value would then tell us the number of bytes
  1223. we would need to allocate.
  1224.  
  1225.      We also can use the fg_getimage routine to retrieve images in text video
  1226. modes.  In text modes, however, there are a few differences we must consider
  1227. when using fg_getimage.  First, the text cursor position, not the graphics
  1228. cursor position, specifies the lower left corner of the image.  Hence, we
  1229. must use the fg_locate routine instead of fg_move to define the image
  1230. location.  Second, the image width is always twice the number of characters
  1231. per image row (that is, for each character we have a character byte and an
  1232. attribute byte).  The fg_getmap routine has no effect when used in a text
  1233. video mode.
  1234.                                           Chapter 10:  Bit-Mapped Images   211
  1235.  
  1236.      Example 10-13 shows a simple use of fg_getimage in text modes.  This
  1237. program is similar to example 10-12, but it runs in an 80-column text mode
  1238. rather than a 320 by 200 graphics mode.  As before, the program will retrieve
  1239. the four characters "text" as an image from the upper left corner of the
  1240. screen and then display it in a different location.  Because the image
  1241. consists of four characters in one row, the image width is 8 bytes and the
  1242. image height is 1.
  1243.  
  1244.                                 Example 10-13.
  1245.  
  1246.                    #include <fastgraf.h>
  1247.                    #include <stdio.h>
  1248.                    #include <stdlib.h>
  1249.                    void main(void);
  1250.  
  1251.                    void main()
  1252.                    {
  1253.                       int old_mode;
  1254.                       char image[8];
  1255.  
  1256.                       old_mode = fg_getmode();
  1257.  
  1258.                       if (fg_testmode(3,1))
  1259.                          fg_setmode(3);
  1260.                       else if (fg_testmode(7,1))
  1261.                          fg_setmode(7);
  1262.                       else {
  1263.                          printf("This program requires\n");
  1264.                          printf("an 80-column display.\n");
  1265.                          exit(1);
  1266.                          }
  1267.  
  1268.                       fg_cursor(0);
  1269.  
  1270.                       fg_setattr(9,7,0);
  1271.                       fg_text("text",4);
  1272.                       fg_waitkey();
  1273.  
  1274.                       fg_locate(0,0);
  1275.                       fg_getimage(image,8,1);
  1276.                       fg_locate(1,1);
  1277.                       fg_drwimage(image,8,1);
  1278.                       fg_waitkey();
  1279.  
  1280.                       fg_setmode(old_mode);
  1281.                       fg_reset();
  1282.                    }
  1283.  
  1284.  
  1285.      Finally, here's a tip that's worth remembering.  In the native EGA and
  1286. VGA graphics modes (13 to 18) and the 16-color SVGA graphics modes (28 and
  1287. 29), the routines for displaying and retrieving mode-specific bit maps can be
  1288. anywhere from 10% to 20% faster if the current graphics x position is an even
  1289. number.  This is because these routines must perform additional bit map
  1290. alignment when displaying or retrieving images starting at odd-numbered
  1291. pixels.
  1292. 212   Fastgraph User's Guide
  1293.  
  1294.  
  1295. Pixel Run Maps
  1296.  
  1297.      The bit maps used with the fg_drawmap, fg_drwimage, and related routines
  1298. can consume array space quite rapidly.  This is especially true if the image
  1299. is large or contains many colors.  For example, a mode-independent bit-mapped
  1300. image that occupies the entire screen in a 320 by 200 graphics mode requires
  1301. 8,000 bytes of space per color.  Fastgraph provides another mode-independent
  1302. image format called pixel run maps, which are more efficient in terms of
  1303. space.  Pixel run maps are structured just like the pixel run files
  1304. introduced in the previous chapter, but the image resides in an array instead
  1305. of a file.
  1306.  
  1307.      Let's return to our familiar triangle example and show how we could use
  1308. a pixel run map to display it.
  1309.  
  1310.                               . . . . * . . . .
  1311.                               . . . * x * . . .
  1312.                               . . * x x x * . .
  1313.                               . * x x x x x * .
  1314.                               * * * * * * * * *
  1315.  
  1316. As before, the pixels indicated by an asterisk (*) are the triangle's
  1317. perimeter, while those indicated by an x represent its interior points.  The
  1318. pixels shown as periods (.) are not part of the triangle itself, but they are
  1319. part of the pixel run map.
  1320.  
  1321.      Using the standard pixel run format introduced in the previous chapter,
  1322. we see it takes 16 pixel runs to store our triangle image as a pixel run map.
  1323. If we want to display the perimeter pixels in color 1, the interior pixels in
  1324. color 2, and the filler area in color 7, the pixel run map would contain 16
  1325. sets of (color,count) pairs:  (1,9), (7,1), (1,1), (2,5), (1,1), (7,3),
  1326. (1,1), (2,3), (1,1), (7,5), (1,1), (2,1), (1,1), (7,7), (1,1), and (7,4).
  1327. Unlike the bit-mapped image formats already discussed, pixel run maps have no
  1328. provision for transparent colors.
  1329.  
  1330.      The Fastgraph routine fg_display displays an image stored as a pixel run
  1331. map.  The fg_display routine expects three arguments.  The first is an array
  1332. containing the pixel runs (passed by reference), the second is the number of
  1333. pixel runs in the array, and the third is the width in pixels of the image.
  1334. As with the other image display routines, the fg_display routine displays the
  1335. image such that its lower left corner is at the graphics cursor position on
  1336. the active video page.  Again, the format of the pixel run map is the same as
  1337. that of a standard pixel run file.  In addition, any display patterns defined
  1338. by fg_pattern also apply to fg_display.
  1339.  
  1340.      Example 10-14 uses the fg_display routine to display the triangle as a
  1341. pixel run map in a 320 by 200 graphics mode.  The program displays the
  1342. triangle against a background of color 7, so the selection of color 7 for the
  1343. filler area was important.  If some other color were chosen, the filler area
  1344. would not blend in with the background.
  1345.  
  1346.                                 Example 10-14.
  1347.  
  1348.                 #include <fastgraf.h>
  1349.                 #include <stdio.h>
  1350.                 #include <stdlib.h>
  1351.                                           Chapter 10:  Bit-Mapped Images   213
  1352.  
  1353.  
  1354.                 void main(void);
  1355.  
  1356.                 char triangle[] = {
  1357.                    1,9, 7,1, 1,1, 2,5, 1,1, 7,3, 1,1, 2,3,
  1358.                    1,1, 7,5, 1,1, 2,1, 1,1, 7,7, 1,1, 7,4
  1359.                    };
  1360.  
  1361.                 void main()
  1362.                 {
  1363.                    int old_mode, new_mode;
  1364.  
  1365.                    new_mode = fg_bestmode(320,200,1);
  1366.                    if (new_mode < 0 || new_mode == 12) {
  1367.                       printf("This program requires a 320 ");
  1368.                       printf("x 200 color graphics mode.\n");
  1369.                       exit(1);
  1370.                       }
  1371.  
  1372.                    old_mode = fg_getmode();
  1373.                    fg_setmode(new_mode);
  1374.  
  1375.                    fg_setcolor(7);
  1376.                    fg_rect(0,319,0,199);
  1377.  
  1378.                    fg_move(156,101);
  1379.                    fg_display(triangle,16,9);
  1380.                    fg_waitkey();
  1381.  
  1382.                    fg_setmode(old_mode);
  1383.                    fg_reset();
  1384.                 }
  1385.  
  1386.      As you might guess, Fastgraph also offers a packed pixel run map image
  1387. format analogous to the packed pixel run file format introduced in the
  1388. previous chapter.  Example 10-15 is the same as example 10-14, but it uses
  1389. fg_displayp rather than fg_display to display the image.  Note the use of
  1390. hexadecimal numbers for defining the packed color values, which of course is
  1391. not necessary but certainly easier to read than expressing the quantities as
  1392. decimal numbers.  As with fg_display, any display patterns defined by
  1393. fg_pattern also apply to fg_displayp.
  1394.  
  1395.                                 Example 10-15.
  1396.  
  1397.                 #include <fastgraf.h>
  1398.                 #include <stdio.h>
  1399.                 #include <stdlib.h>
  1400.                 void main(void);
  1401.  
  1402.                 char triangle[] = {
  1403.                    0x17,9,1, 0x12,1,5, 0x17,1,3, 0x12,1,3,
  1404.                    0x17,1,5, 0x12,1,1, 0x17,1,7, 0x17,1,4
  1405.                    };
  1406.  
  1407.                 void main()
  1408.                 {
  1409.                    int old_mode, new_mode;
  1410. 214   Fastgraph User's Guide
  1411.  
  1412.  
  1413.                    new_mode = fg_bestmode(320,200,1);
  1414.                    if (new_mode < 0 || new_mode == 12) {
  1415.                       printf("This program requires a 320 ");
  1416.                       printf("x 200 color graphics mode.\n");
  1417.                       exit(1);
  1418.                       }
  1419.  
  1420.                    old_mode = fg_getmode();
  1421.                    fg_setmode(new_mode);
  1422.  
  1423.                    fg_setcolor(7);
  1424.                    fg_rect(0,319,0,199);
  1425.  
  1426.                    fg_move(156,101);
  1427.                    fg_displayp(triangle,16,9);
  1428.                    fg_waitkey();
  1429.  
  1430.                    fg_setmode(old_mode);
  1431.                    fg_reset();
  1432.                 }
  1433.  
  1434.  
  1435.      Both the fg_display and fg_displayp routines require the pixel run image
  1436. to be stored in an array.  In examples 10-14 and 10-15, the image is defined
  1437. within the program itself.  We can also use these routines in place of
  1438. fg_dispfile when the image is stored in a file if we first read the file
  1439. contents into an array.  Example 10-16 demonstrates this procedure.  The
  1440. program displays two identical images stored in files, one in standard pixel
  1441. run format and the other in packed pixel run format.
  1442.  
  1443.      The first image, in standard pixel run format, is in the file CORAL.SPR.
  1444. Note the program must open the file for reading in binary mode ("rb" in the
  1445. call to fopen).  The program reads the file's entire contents into the
  1446. pixel_runs array, whose size must be at least as large as the file size.
  1447. Because the image is stored in standard pixel run format, the number of pixel
  1448. runs is one-half the file size.  The program then uses the fg_move routine to
  1449. establish the lower left corner of the screen as the graphics cursor position
  1450. and then calls fg_display to display the image.  The image fills the entire
  1451. screen, so its width is 320 pixels.
  1452.  
  1453.      After waiting for a keystroke, the program similarly displays the second
  1454. image.  This image is in the file CORAL.PPR and is stored in packed pixel run
  1455. format.  Because the image is packed, the number of pixel runs is two-thirds
  1456. the file size.  The program then clears the previous image from the screen
  1457. and calls fg_displayp to display the image.  After another keystroke, the
  1458. program restores the original video mode and screen attributes and returns to
  1459. DOS.
  1460.  
  1461.                                 Example 10-16.
  1462.  
  1463.              #include <fastgraf.h>
  1464.              #include <io.h>
  1465.              #include <stdio.h>
  1466.              #include <stdlib.h>
  1467.              void main(void);
  1468.  
  1469.                                           Chapter 10:  Bit-Mapped Images   215
  1470.  
  1471.  
  1472.              char pixel_runs[20000];
  1473.  
  1474.              void main()
  1475.              {
  1476.                 long filelength();
  1477.                 FILE *stream;
  1478.                 int file_size, run_count;
  1479.                 int old_mode, new_mode;
  1480.  
  1481.                 new_mode = fg_bestmode(320,200,1);
  1482.                 if (new_mode < 0 || new_mode == 12) {
  1483.                    printf("This program requires a 320 ");
  1484.                    printf("x 200 color graphics mode.\n");
  1485.                    exit(1);
  1486.                    }
  1487.  
  1488.                 old_mode = fg_getmode();
  1489.                 fg_setmode(new_mode);
  1490.  
  1491.                 stream = fopen("CORAL.SPR","rb");
  1492.                 file_size = (int)(filelength(fileno(stream)));
  1493.                 fread(pixel_runs,sizeof(char),file_size,stream);
  1494.                 fclose(stream);
  1495.                 run_count = file_size / 2;
  1496.                 fg_move(0,199);
  1497.                 fg_display(pixel_runs,run_count,320);
  1498.                 fg_waitkey();
  1499.  
  1500.                 stream = fopen("CORAL.PPR","rb");
  1501.                 file_size = (int)(filelength(fileno(stream)));
  1502.                 fread(pixel_runs,sizeof(char),file_size,stream);
  1503.                 fclose(stream);
  1504.                 run_count = file_size / 3 * 2;
  1505.                 fg_erase();
  1506.                 fg_displayp(pixel_runs,run_count,320);
  1507.                 fg_waitkey();
  1508.  
  1509.                 fg_setmode(old_mode);
  1510.                 fg_reset();
  1511.              }
  1512.  
  1513.  
  1514. Masking Maps
  1515.  
  1516.      It is not possible to include color 0 pixels in an image displayed with
  1517. the fg_drwimage, fg_clpimage, fg_revimage, or fg_flpimage routines.  This is
  1518. because these routines consider color 0 pixels to be transparent, which means
  1519. such pixels do not affect the corresponding pixels in video memory.  There
  1520. are times, however, when you will want color 0 pixels to be destructive, or
  1521. replace the video memory contents.
  1522.  
  1523.      Consider again the arrow image of example 10-8.  In that example, we
  1524. displayed a white (color 3) arrow against a black (color 0) background in the
  1525. standard CGA four-color graphics mode.  Suppose, though, that we want to do
  1526. just the opposite -- display a black (color 0) arrow against a white (color
  1527. 3) background.  We could of course use fg_putimage, fg_drawmap, or one of the
  1528. 216   Fastgraph User's Guide
  1529.  
  1530.  
  1531. routines for displaying pixel run maps, but these methods do not support
  1532. clipping or reversing an image.  There are, however, four Fastgraph routines
  1533. designed just for this purpose.  These routines are fg_drawmask, fg_clipmask,
  1534. fg_revmask, and fg_flipmask.
  1535.  
  1536.      Each of these routines uses a data structure called a masking map.  A
  1537. masking map is similar in structure to a pixel run map, but it does not
  1538. include any information about colors.  Instead, it consists of a series of
  1539. pixel runs that alternate between protected and unprotected pixels.  An
  1540. example might best clarify this.
  1541.  
  1542.      Once again, here is the arrow image of example 10-8.
  1543.  
  1544.                              . . . . . . * . . .
  1545.                              . . . . . . * * . .
  1546.                              * * * * * * * * * .
  1547.                              * * * * * * * * * *
  1548.                              * * * * * * * * * .
  1549.                              . . . . . . * * . .
  1550.                              . . . . . . * . . .
  1551.  
  1552. This time, though, we want the arrow to appear in color 0.  Put another way,
  1553. we need the "period" pixels (.) to protect video memory, while we want the
  1554. "asterisk" pixels (*) to zero video memory.  Looking at this problem from the
  1555. perspective of a pixel run map, we have an alternating series of "protect"
  1556. and "zero" runs.  We don't need any information about pixel colors, just
  1557. whether to protect or to zero video memory.
  1558.  
  1559.      This is precisely the structure of a masking map.  Starting from the
  1560. lower left corner of the image and proceeding to the right, wrapping up to
  1561. the next row when needed, we could represent this image as a masking map with
  1562. 6 protected pixels, 1 zeroed pixel, 9 protected pixels, 2 zeroed pixels, and
  1563. so on.  In general, the structure of a masking map is as follows.
  1564.  
  1565.                       [1]   length of 1st protect run
  1566.  
  1567.                       [2]   length of 1st  zero   run
  1568.  
  1569.                       [3]   length of 2nd protect run
  1570.  
  1571.                       [4]   length of 2nd  zero   run
  1572.                                         .
  1573.                                         .
  1574.                                         .
  1575.                                         .
  1576.                                         .
  1577.                     [n-2]   length of final protect run
  1578.  
  1579.                     [n-1]   length of final  zero   run
  1580.  
  1581.      Looking at this diagram, we see that the even-numbered array elements
  1582. hold the length of the "protect" runs, and the odd-numbered elements hold the
  1583. length of the "zero" runs.  If you need the first run to be a "zero" run,
  1584. just include a "protect" run of length zero as the first element of the
  1585. array.  If the final run is a "protect" run, you do not need to include a
  1586.                                           Chapter 10:  Bit-Mapped Images   217
  1587.  
  1588.  
  1589. zero-length "zero" run at the end of the array.  Finally, if either type of
  1590. run exceeds 255 pixels, you'll need to split this into two or more pixel
  1591. runs.  In this case, be sure to include a zero-length run of the other type
  1592. between the two array elements.
  1593.  
  1594.      Example 10-17 illustrates the use of a masking map through the
  1595. fg_drawmask, fg_clipmask, fg_revmask, and fg_flipmask routines in the
  1596. standard CGA four-color graphics mode (mode 4) to draw a black (color 0)
  1597. arrow against a white background.  These four routines are respectively
  1598. analogous to the fg_drwimage, fg_clpimage, fg_revimage, and fg_flpimage
  1599. routines, but they use masking maps rather than bit maps.  The first argument
  1600. of each routine is the masking map array (passed by reference), the second
  1601. argument is the number of runs (that is, the number of elements) in the
  1602. masking map array, and the third argument is the width in pixels of the
  1603. image.
  1604.  
  1605.                                 Example 10-17.
  1606.  
  1607.                 #include <fastgraf.h>
  1608.                 #include <stdio.h>
  1609.                 #include <stdlib.h>
  1610.                 void main(void);
  1611.  
  1612.                 char arrow[] = {6,1,9,2,2,9,1,19,7,2,8,1};
  1613.  
  1614.                 void main()
  1615.                 {
  1616.                    int old_mode;
  1617.  
  1618.                    if (fg_testmode(4,1) == 0) {
  1619.                       printf("This program requires a 320 ");
  1620.                       printf("x 200 CGA graphics mode.\n");
  1621.                       exit(1);
  1622.                       }
  1623.  
  1624.                    old_mode = fg_getmode();
  1625.                    fg_setmode(4);
  1626.                    fg_setclip(0,15,0,199);
  1627.  
  1628.                    fg_setcolor(3);
  1629.                    fg_rect(0,319,0,199);
  1630.  
  1631.                    fg_move(10,10);
  1632.                    fg_drawmask(arrow,12,10);
  1633.                    fg_move(10,20);
  1634.                    fg_clipmask(arrow,12,10);
  1635.                    fg_move(10,30);
  1636.                    fg_revmask(arrow,12,10);
  1637.                    fg_move(10,40);
  1638.                    fg_flipmask(arrow,12,10);
  1639.                    fg_waitkey();
  1640.  
  1641.                    fg_setmode(old_mode);
  1642.                    fg_reset();
  1643.                 }
  1644.  
  1645. 218   Fastgraph User's Guide
  1646.  
  1647.      One of the more useful features of masking maps is the ability to clear
  1648. a portion of video memory before placing an image there.  This technique
  1649. provides an efficient, simple way to include color 0 pixels in an image.  It
  1650. is especially effective when displaying large or dithered images because the
  1651. masking map is typically much smaller than the bit map required by fg_drawmap
  1652. or its related routines.  Example 10-18 illustrates this process in the
  1653. standard CGA four-color graphics mode (mode 4) by displaying our arrow image
  1654. against a colored background.  In this example, the arrow has a white (color
  1655. 3) perimeter and a black (color 0) interior.
  1656.  
  1657.      The program displays the arrow in two steps.  It first uses fg_drawmask
  1658. to clear the video memory where the arrow will be displayed.  It then draws
  1659. the arrow's perimeter using the fg_drwimage routine.  The interior pixels in
  1660. the perimeter bit map are transparent, but since we just zeroed that video
  1661. memory, they appear in color 0.  Note we could improve this example by
  1662. creating a smaller masking map that only applies to the rectangle inscribing
  1663. the arrow's interior.  That is, we don't need to zero the video memory under
  1664. the arrow's perimeter because we will immediately display other pixels there.
  1665.  
  1666.                                 Example 10-18.
  1667.  
  1668.               #include <fastgraf.h>
  1669.               #include <stdio.h>
  1670.               #include <stdlib.h>
  1671.               void main(void);
  1672.  
  1673.               char arrow_white[] = {
  1674.                  0x00,0x0C,0x00, 0x00,0x0F,0x00, 0xFF,0xFC,0xC0,
  1675.                  0xC0,0x00,0x30, 0xFF,0xFC,0xC0, 0x00,0x0F,0x00,
  1676.                  0x00,0x0C,0x00
  1677.                  };
  1678.               char arrow_black[] = {6,1,9,2,2,9,1,19,7,2,8,1};
  1679.  
  1680.               void main()
  1681.               {
  1682.                  int old_mode;
  1683.  
  1684.                  if (fg_testmode(4,1) == 0) {
  1685.                     printf("This program requires a 320 ");
  1686.                     printf("x 200 CGA graphics mode.\n");
  1687.                     exit(1);
  1688.                     }
  1689.  
  1690.                  old_mode = fg_getmode();
  1691.                  fg_setmode(4);
  1692.  
  1693.                  fg_setcolor(2);
  1694.                  fg_rect(0,319,0,199);
  1695.  
  1696.                  fg_move(10,10);
  1697.                  fg_drawmask(arrow_black,12,10);
  1698.                  fg_drwimage(arrow_white,3,7);
  1699.                  fg_waitkey();
  1700.  
  1701.                  fg_setmode(old_mode);
  1702.                  fg_reset();
  1703.               }
  1704.                                           Chapter 10:  Bit-Mapped Images   219
  1705.  
  1706.  
  1707. Summary of Bit-Mapped Image Display Routines
  1708.  
  1709.      This section summarizes the functional descriptions of the Fastgraph
  1710. routines presented in this chapter.  More detailed information about these
  1711. routines, including their arguments and return values, may be found in the
  1712. Fastgraph Reference Manual.
  1713.  
  1714.      For all bit-mapped image routines, images are displayed or retrieved so
  1715. their lower left corner is at the graphics cursor position (or text cursor
  1716. position for those routines that also work in text video modes).
  1717.  
  1718.      FG_CLIPMASK displays a clipped image stored as a masking map.  This
  1719. routine has no effect when used in a text video mode.
  1720.  
  1721.      FG_CLPIMAGE displays a clipped image stored as a mode-specific bit map.
  1722. Color 0 pixels are considered transparent.  This routine has no effect when
  1723. used in a text video mode.
  1724.  
  1725.      FG_DISPLAY displays an image stored in Fastgraph's standard pixel run
  1726. format, where the image resides in an array.  This routine has no effect when
  1727. used in a text video mode.
  1728.  
  1729.      FG_DISPLAYP displays an image stored in Fastgraph's packed pixel run
  1730. format, where the image resides in an array.  This routine has no effect when
  1731. used in a text video mode.
  1732.  
  1733.      FG_DRAWMAP displays an image stored as a mode-independent bit map.  This
  1734. routine has no effect when used in a text video mode.
  1735.  
  1736.      FG_DRAWMASK displays an image stored as a masking map.  This routine has
  1737. no effect when used in a text video mode.
  1738.  
  1739.      FG_DRWIMAGE displays an image stored as a mode-specific bit map.  Color
  1740. 0 pixels are considered transparent.
  1741.  
  1742.      FG_FLIPMASK displays a reversed clipped image stored as a masking map.
  1743. This routine has no effect when used in a text video mode.
  1744.  
  1745.      FG_FLPIMAGE displays a reversed clipped image stored as a mode-specific
  1746. bit map.  Color 0 pixels are considered transparent.  This routine has no
  1747. effect when used in a text video mode.
  1748.  
  1749.      FG_GETIMAGE retrieves an image as a mode-specific bit map.
  1750.  
  1751.      FG_GETMAP retrieves an image as a mode-independent bit map.  This
  1752. routine has no effect when used in a text video mode.
  1753.  
  1754.      FG_IMAGESIZ determines the number of bytes required to store a mode-
  1755. specific bit-mapped image of specified dimensions.
  1756.  
  1757.      FG_PUTIMAGE displays an image stored as a mode-specific bit map.  No
  1758. support is provided for transparent pixels.
  1759. 220   Fastgraph User's Guide
  1760.  
  1761.  
  1762.      FG_REVIMAGE displays a reversed image stored as a mode-specific bit map.
  1763. Color 0 pixels are considered transparent.  This routine has no effect when
  1764. used in a text video mode.
  1765.  
  1766.      FG_REVMASK displays a reversed image stored as a masking map.  This
  1767. routine has no effect when used in a text video mode.
  1768.